package com.cs.framework.jdbc.hibernate3.session;

import java.util.Properties;

import javax.sql.DataSource;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean;

import com.cs.framework.jdbc.common.session.CSSessionFactory;

/**
 * Session工厂抽象类
 * 
 * @author hedongzhou
 * 
 */
public abstract class AbstractHibernateSessionFactory implements CSSessionFactory, FactoryBean<SessionFactory>,
		InitializingBean {

	/**
	 * 数据源
	 */
	protected DataSource dataSource;

	/**
	 * 支持Hibernate注解的SessionFactory
	 */
	protected AnnotationSessionFactoryBean sessinFactoryBean;

	/**
	 * hibernate属性配置文件路径
	 */
	protected String propertiesPath;

	/**
	 * hibernate属性配置信息
	 */
	protected Properties hibernateProperties;

	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}

	public void setPropertiesPath(String propertiesPath) {
		this.propertiesPath = propertiesPath;
	}

	public SessionFactory getObject() throws Exception {
		return sessinFactoryBean.getObject();
	}

	public Class<? extends SessionFactory> getObjectType() {
		return SessionFactory.class;
	}

	public boolean isSingleton() {
		return true;
	}

	public void afterPropertiesSet() throws Exception {
		buildSessionFactory();
	}

}
